<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>菜品类别编辑</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <i th:replace="~{common :: baseUrl}"></i>
</head>
<body>
<form class="layui-form layui-form-pane" action=""  >


        <div class="layui-form-item">
            <label class="layui-form-label">原料名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">类别</label>
            <div class="layui-input-inline">
                <select name="categoryId" lay-verify="required">
                    <option value=''>请选择分类名称</option>
                    <option th:each="f : ${categorys}"  th:value="${f.id}" th:text="${f.categoryName}" ></option>
                </select>
            </div>
        </div>





        <div class="layui-form-item">
            <label class="layui-form-label">采购单位</label>
            <div class="layui-input-inline">
                <select name="purchaseUnit" id="purchaseUnit" lay-filter="purchaseUnit"  >
                    <option th:each="f : ${units}"  th:value="${f.id}" th:text="${f.unit}" ></option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">采购单价</label>
            <div class="layui-input-inline" style="width: 140px;">
                <input type="text" name="unitPriceString"    lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline" style="width: 40px;">
                <input type="text" id="unitPriceUnitf" style="background-color:#e2e2e2;"   placeholder="xx" autocomplete="off" class="layui-input">
            </div>
        </div>

    <div class="layui-form-item">
        <label class="layui-form-label">库存单位</label>
        <div class="layui-input-inline">
            <select name="repertoryUnit" id="repertoryUnit" lay-filter="repertoryUnit"  >
                <option th:each="f : ${units}"  th:value="${f.id}" th:text="${f.unit}" ></option>
            </select>
        </div>
    </div>

        <div class="layui-form-item">
            <label class="layui-form-label">规格换算</label>
            <div class="layui-input-inline" style="width: 80px;">
                <input type="text" name="conversion"   lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">

            </div>
            <div class="layui-input-inline" style="width: 30px;">
                <input type="text"  id="repertoryUnitf" readonly="readonly" style="background-color:transparent;border:0;"   placeholder="xx" autocomplete="off" class="layui-input">

            </div>
            <div class="layui-input-inline" style="width: 30px;">
                <input type="text"   readonly="readonly" style="background-color:transparent;border:0;"   placeholder="= 1" autocomplete="off" class="layui-input">

            </div>
            <div class="layui-input-inline" style="width: 40px;">
                <input type="text" id="purchaseUnitf" style="background-color:transparent;border:0;"   placeholder="xx" autocomplete="off" class="layui-input">
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">库存</label>
            <div class="layui-input-inline">
                <input type="text" name="nowRepertory"    lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">库存范围</label>
                <div class="layui-input-inline" style="width: 140px;">
                    <input type="text" class="layui-input" name="repertoryLowLine"   placeholder="库存过低预警线">
                </div>
                <div class="layui-input-inline" style="width: 40px;">
                    <input type="text" id="lowLineUnitf" style="background-color:#e2e2e2;"   placeholder="xx" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline" style="width: 140px;">
                    <input type="text" class="layui-input"  name="repertoryHighLine"  placeholder="库存超出预警线">
                </div>
                <div class="layui-input-inline" style="width: 40px;">
                    <input type="text" id="highLineUnitf" style="background-color:#e2e2e2;"   placeholder="xx" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>



<input hidden name="merchantsId" th:value="${merchantsId}">




    <div class="layui-form-item" >
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>



</body>
<script th:src="@{/layui/layui.js}"></script>
<script th:inline="none">
    //JavaScript代码区域
    layui.use(['element','form','upload','layer','laydate'], function() {
        var element = layui.element;
        var form = layui.form;
        var upload = layui.upload;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var $ = layui.$;

        //初始化单位
        $(function () {
            var purchaseUnit = $("#purchaseUnit ").find("option:selected").text()
            var repertoryUnit = $("#repertoryUnit ").find("option:selected").text()


            $("#unitPriceUnitf").val(purchaseUnit)
            $("#lowLineUnitf").val(repertoryUnit)
            $("#highLineUnitf").val(repertoryUnit)
            $("#purchaseUnitf").val(purchaseUnit);

            $("#repertoryUnitf").val(repertoryUnit)
        });


        //监听采购单位下拉列表的改变，并赋值
        form.on('select(purchaseUnit)', function(data){
            var purchaseUnit = $("#purchaseUnit ").find("option:selected").text()

            $("#unitPriceUnitf").val(purchaseUnit)

            $("#purchaseUnitf").val(purchaseUnit);
        });

        //监听入库单位下拉列表的改变，并赋值
        form.on('select(repertoryUnit)', function(data){
            var repertoryUnit = $("#repertoryUnit ").find("option:selected").text()
            $("#repertoryUnitf").val(repertoryUnit)
            $("#lowLineUnitf").val(repertoryUnit)
            $("#highLineUnitf").val(repertoryUnit)
        });




        //提交
        form.on('submit(sub)', function(data){

            //发送ajax请求  编辑APP信息
            $.ajax({
                url:baseUrl+"food/material/add",
                data:data.field,
                type:"post",
                dataType:"json",
                success:function (result) {
                    if (result.code==0){
                        layer.open({
                            title: '编辑菜品信息'
                            ,content: '恭喜你! 编辑菜品信息成功！'
                            ,end:function () {
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                        });
                    }else {
                        layer.open({
                            title: '编辑菜品信息'
                            ,content: result.msg
                        });
                    }
                },
                error:function () {
                    layer.msg("服务器原地爆炸,请联系管理员!!!");
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

        });





    });

</script>
</html>